home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8"?>
- <!-- ===========================================================
- Styelsheet: GroupProdMuenchian.xsl
- Category: Grouping
- Author: David Silverlight
- HeadGeek@xmlpitstop.com
- Created: 2001-05-16
- ================================================================ -->
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- <xsl:output method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" />
-
- <!--
- Step 1: Define the primary key to be used in the Muenchian grouping. The
- beautiful thing about the xsl:key element in our example is that once we
- know the "region", we can easily find all of the products that match that region.
- The xsl:key element (different from the key() function) is defined as follows:-->
- <xsl:key name="products" match="product" use="region" />
-
- <!-- Template for our root rule -->
- <xsl:template match="/">
- <html>
- <head>
- <title>FilteringSorting - Sorting records by parameters</title>
- <style type="text/css">
- H1 {COLOR: red; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- H2 {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .head {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 14pt;}
- .subhead {COLOR: darkblue; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- .text {COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: 12pt;}
- TH {COLOR: white; FONT-FAMILY: Arial; background-color: darkblue;}
- TD {COLOR: darkblue; FONT-FAMILY: Arial}
- TR { background-color: beige; }
- BODY { background-color: beige; }
- </style>
- </head>
- <body>
- <xsl:apply-templates />
- </body>
- </html>
- </xsl:template>
-
- <!-- Template for our "products" rule -->
- <xsl:template match="products">
- <h2>Grouping of Products by Region, then by Product Name</h2>
-
- <!-- Step 2: Loop through the unique regions (the primary key) in our document. -->
- <!-- <xsl:for-each select="product[generate-id(.)=generate-id(key('products',region))]"> -->
- <xsl:for-each select="product[count(.|key('products',region)[1]) = 1]">
- <!-- Sort Primary key by name in ascending order -->
- <xsl:sort select="name" order="ascending" />
- <!-- Display the region as our table header -->
- <h3>
- <xsl:value-of select="region" />
- <xsl:text> region</xsl:text>
- </h3>
- <!--Display all nodes for a given region in a table-->
- <table border="1">
- <tr>
- <th>Product Name</th>
- <th>Price</th>
- <th>Region</th>
- </tr>
- <!-- For each value in our key collection for the given region,
- display values -->
- <xsl:for-each select="key('products',region)">
- <!--
- The expression "key('products',region)" will return all of the "product"
- elements from the key table whose "use=" expression defined in xsl:key
- (see xsl:key at top) evaluated to the same value as the "region" child
- of the current element. In the the example, we specified use="region".
- If region has a value of "SouthWest", then all of the product elements from
- the key table that contain a child element with a value of "SouthWest" will
- be returned.
- -->
- <!--Sort our secondary key, product nodes, by name-->
- <xsl:sort select="name" />
- <tr>
- <td>
- <xsl:value-of select="name" />
- </td>
- <td>
- <xsl:value-of select="price" />
- </td>
- <td>
- <xsl:value-of select="region" />
- </td>
- </tr>
- </xsl:for-each>
- </table>
- <br />
- <br />
- </xsl:for-each>
- </xsl:template>
- </xsl:stylesheet>
-